console.clear();
import { showTaskUI, uiHp } from "./ui";
uiHp();

world.onPlayerJoin(async({entity})=>{
    remoteChannel.sendClientEvent(entity, {
        type: 'ok',
        data: {
            text: 'text',
        }
    });
    
    setTimeout(()=>{
        //entity.assignmentid = 0;//测试
        gainTask(entity,descriptions[entity.assignmentid],1);
        entity.taskInterval = setInterval(()=>{
            if (entity.oldAssignmentid != entity.assignmentid){
                gainTask(entity,descriptions[entity.assignmentid],0);
            }
        },300)
    },1000)
});

world.onPlayerLeave(async({entity})=>{
    clearInterval(entity.taskInterval);
});



let descriptions:string[] = ['完成新手指导','寻找[召唤核心]挑战','暂无任务'];


/**
 * 获得任务ui显示
 * @param entity 玩家实体
 * @param description 任务描述
 * @param type 发送UI类型(若第一次发出请填1,若是替换任务显示请填0,若是不显示动画直接更改文字请填2)
 */
export async function gainTask(entity:GamePlayerEntity,description:string,type:0|1|2){
    entity.oldAssignmentid = entity.assignmentid;
    showTaskUI(entity,description,type);
}